package com.gmail.blackdog1987.carcare.network.request.builder;

import android.content.Context;

import com.gmail.blackdog1987.carcare.Constant;
import com.gmail.blackdog1987.carcare.db.dao.UserDao;
import com.gmail.blackdog1987.carcare.network.request.RequestBuilder;
import com.gmail.blackdog1987.carcare.util.DeviceUtils;
import com.gmail.blackdog1987.carcare.util.LogUtil;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

public class OrderCarChangeRequestBuilder extends RequestBuilder {

	private static final String TAG = OrderCarChangeRequestBuilder.class.getSimpleName();
	private String shopid;
	private String detailid;
	private String name;
	private String phone;

	public OrderCarChangeRequestBuilder setShopid(String shopid) {
		this.shopid = shopid;
		return this;
	}

	public OrderCarChangeRequestBuilder setDetailid(String detailid) {
		this.detailid = detailid;
		return this;
	}

	public OrderCarChangeRequestBuilder setName(String name) {
		this.name = name;
		return this;
	}

	public OrderCarChangeRequestBuilder setPhone(String phone) {
		this.phone = phone;
		return this;
	}

	public OrderCarChangeRequestBuilder setInfo(String info) {
		this.info = info;
		return this;
	}

	private String info;

	@Override
	public RequestParams buildRquest() {
		RequestParams params = new RequestParams();
		params.put("shopid", shopid);
		params.put("detailid", detailid);
		params.put("userid", String.valueOf(new UserDao().getUser().id));
		params.put("name", name);
		params.put("phone", phone);
		params.put("info", info);
		return params;
	}

	@Override
	public void postJsonRequest(Context context, AsyncHttpResponseHandler handler) {

		RequestParams params = buildRquest();

		AsyncHttpClient client = new AsyncHttpClient();
		client.setTimeout(Constant.TIMEOUT);
		client.setUserAgent(DeviceUtils.OS.getName());

		client.post(Constant.Action.ORDER_CARCHANGE, params, handler);
		LogUtil.d(TAG, "post : " + params);
	}

}
